<?php

/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2017/12/21
 * Time: 下午5:09
 */
class Shopuser_model extends CI_Model
{

    public function __construct()
    {
        $this->load->database();
        $this->load->helper("common");
    }

    //商户登录
    public function login($tel, $session_key, $type = '')
    {
        if ($tel && $session_key) {

            if ($type == '') {
                $shopTelInfo = $this->db->query("select * from app_shop_tel where tel = '$tel'")->row_array();
                if ($shopTelInfo) {
                } else {
                    send_json(array('code' => 4006, 'data' => '', 'msg' => "该手机号无权登陆"));
                }
            }

            $data_arr        = array();
            $data_arr['tel'] = $tel;
            if ($userInfo = $this->db->query("select * from app_user where session_key = '$session_key'")->row_array()) {
                if ($userInfo['status'] == 0) {
                    send_json(array('code' => 4006, 'data' => '', 'msg' => "该账户已被冻结"));
                }

                $where = array('session_key' => $session_key);
                $res   = $this->db->where($where)->update('app_user', $data_arr);
            } else {
                send_json(array('code' => 4002, 'data' => '', 'msg' => "授权登陆已过期,请重新授权登陆"));
            }

            return true;
        } else {
            return false;
        }
    }

}
